//
//  LBCategoryPopuViewCell.m
//  AFNetworking
//
//  Created by luckyRoy on 2018/1/31.
//

#import "LBCategoryPopuViewCell.h"
#import "UIColor+LBColor.h"
#import "LBCategoryModel.h"
#import "Masonry.h"
#import "NSString+LBString.h"

@interface LBCategoryPopuViewCell ()

@property (nonatomic, strong) UIView *bgView;

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UIImageView *delImageView;

@property (nonatomic, copy) NSString *title;

@end

@implementation LBCategoryPopuViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createAllView];
    }
    return self;
}

- (void)createAllView
{
    [self addSubview:self.bgView];
    [self addSubview:self.delImageView];
    
    CGFloat space = 3;
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(space);
        make.left.bottom.equalTo(self);
        make.right.offset(-space);
    }];
    [self.delImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self);
        make.top.equalTo(self);
    }];
}

#pragma mark - setter

- (void)fac_updateUIViewByModel:(id)cellModel
{
    LBCategoryModel *theCellModel = cellModel;
    
    NSString *showTitle = theCellModel.name;
    [self.titleLabel setText:showTitle];
}

#pragma mark - getter

- (UIView *)bgView
{
    if (!_bgView) {
        _bgView = [[UIView alloc]init];
        _bgView.backgroundColor = [UIColor colorWithRed:244/255.0 green:250/255.0 blue:255/255.0 alpha:1];
        _bgView.layer.cornerRadius = 4.0;
        
        [_bgView addSubview:self.titleLabel];
        
        CGFloat space = 10;
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_bgView).offset(5);
            make.right.equalTo(_bgView).offset(-space);
            make.top.bottom.equalTo(_bgView);
        }];
    }
    return _bgView;
}

- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.textColor = [UIColor blue];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.font = LBCategoryPopuViewCellFont;
    }
    return _titleLabel;
}

- (UIImageView *)delImageView
{
    if (!_delImageView) {
        _delImageView = [[UIImageView alloc]init];
        [_delImageView setImage:[UIImage imageNamed:@"Category.bundle/lb_category_close"]];
    }
    return _delImageView;
}

+ (CGFloat)fac_heightForViewByModel:(id)cellModel
{
    CGFloat totalHeight = 0;
    
    totalHeight += 45;
    
    return totalHeight;
}

+ (CGFloat)realCellWidthByModel:(id)model
{
    LBCategoryModel *cellModel = model;
    
    NSString *showTitle = cellModel.name;
    
    CGFloat width = [NSString getTextSizeWithContent:showTitle Font:LBCategoryPopuViewCellFont Width:([[UIScreen mainScreen] bounds].size.width - 20)].width;
    
    CGFloat space = 10;
    
    width += space * 2;
    
    return width;
}

@end
